package com.daniel.cms.service;

import com.daniel.cms.entity.UserEntity;
import com.daniel.cms.mapper.UserMapper;
import com.daniel.cms.utils.ResultEnum;
import com.daniel.cms.utils.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;


/**
 * 详细说明
 *
 * @author Daniel
 * @version V1.0
 * @date 2020/4/21 10:49
 */
@Slf4j
@Service
public class UserService {
	@Autowired
	UserMapper mapper;

	/**
	 * 创建用户
	 *
	 * @param entity 请求实体
	 * @return Mes
	 */
	public ResultVO create(UserEntity entity) {
		try {
			entity.setPassword(DigestUtils.md5DigestAsHex(entity.getRule().getBytes()));
			int result = mapper.insert(entity);
			return result > 0 ? new ResultVO(ResultEnum.SUCCESS, "") : new ResultVO(ResultEnum.FAILED, "");
		} catch (Exception ex) {
			return new ResultVO(ResultEnum.ERROR, "");
		}
	}

}
